<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>结算</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="__TMPL__/public/order/css/result.css"/>
    <script type="text/javascript" src="__TMPL__/public/order/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="__TMPL__/public/assets/js/layer/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="__TMPL__/public/assets/css/mobileSelect.css"/>
    <script src="__TMPL__/public/assets/js/mobileSelect.min.js"></script>
</head>
<body>
<header>
    <div class="content" style="border-bottom: 1px solid rgba(215, 215, 215, 0.29);">
        <a href="{:url('shop/good/car')}"></a>
        <a>订单</a>
        <a href="javacript:;"></a>
    </div>
</header>
<empty name="address_list">
    <div class="new" >
        <a href="{:url('user/profile/address',array('type'=>1))}"><div>＋新建收货地址</div></a>
        <img src="__TMPL__/public/order/img/border.png"/>
    </div>
</empty>
<notempty name="address_list">
<div class="address" onclick="location.href='{:url(\'user/profile/address\',array(\'type\'=>1))}'">
    <p>{$address_list.0.consigner}</p>
    <p>{$address_list.0.mobile}</p>
    <p>{:get_city_info($address_list[0]['province'],$address_list[0]['city'],$address_list[0]['district'])}{$address_list[0]['address']}</p>
</div>
</notempty>
<div class="shops">
    <foreach name="car_list" item="vo">
        <php>
            $more=json_decode($vo['goods']['more'],true);
            if($vo['is_checked']==1){
        </php>
            <div>
                <img src="{:cmf_get_image_preview_url($more['thumbnail'])}"/>
                <p>{$vo.goods.post_title}</p>
                <p><span>￥<b>{$vo.goods.post_price}</b>+{$vo.goods.post_score}积分</span><span>×{$vo.num}</span></p>
            </div>
        <php>}</php>

    </foreach>
</div>

<div class="cost">
    <div class="item-options">
        <label>买家留言</label>
        <textarea id="leavemessage" placeholder="给卖家留言" maxlength="100"></textarea>
    </div>
    <div class="cost1"><span>发票</span><span id="receipt" style="color:#666">不开发票</span></div>
    <div class="cost1 receipt_type" style="display: none"><span>发票类型</span><span id="receipt_type" style="color:#666">个人</span></div>
    <div class="cost1 receipt_info" style="display: none"><span>公司名称</span><span style="color:#666"><input type="text" id="receipt_info_name" placeholder="请填写公司名称"></span></div>
    <div class="cost1 receipt_info" style="display: none"><span>纳税人识别号</span><span style="color:#666"><input type="text" id="receipt_info_code" placeholder="请填写纳税人识别号"></span></div>
    <div class="cost1" ><span>运费</span><span>￥{$fright}</span></div>
    <div class="cost1"><span>小计</span><span>{$data['count_price']}</span></div>
    {$message}
    <div class="payway">
        <div class="wxpay way">
            <img src="__TMPL__/public/order/img/wx.png"/>
            <span>微信支付</span>
            <i><img src="__TMPL__/public/order/img/icon_radio3.png" class="fal" style="display: none;"/>
                <img src="__TMPL__/public/order/img/icon_radio4.png"  class="tru"/>
            </i></div>
    </div>
</div>
<div class="total">
    <div>应付：<span>￥{$count_yifu_price} <gt name="count_yifu_score" value="0">+{$count_yifu_score}积分</gt></span></div>
    <div class="to_pay">立即支付</div>
</div>
</body>

<input type="hidden" id="address_list" value="{$address_list.0.id|default='0'}">
<input type="hidden" id="h_receipt" value="0">
<input type="hidden" id="h_receipt_type" value="0">

<script type="text/javascript">

    $(function () {
        var mobileSelect1 = new MobileSelect({
            trigger: '#receipt',
            title: '发票',
            wheels: [
                {data:['不开发票','增值税发票']}
            ],
            callback:function(indexArr, data){
                console.log(indexArr); //返回选中的json数据
                if(indexArr==0){
                    $('#h_receipt').val(0)
                    $('.receipt_type').hide();
                    $('.receipt_info').hide();
                }
                if(indexArr==1){
                    $('#h_receipt').val(1)
                    $('.receipt_type').show();
                }
            }
        });
        var mobileSelect2 = new MobileSelect({
            trigger: '#receipt_type',
            title: '发票类型',
            wheels: [
                {data:['个人','公司']}
            ],
            callback:function(indexArr, data){
                if(indexArr==0){
                    $('#h_receipt_type').val(0)
                    $('.receipt_info').hide();
                }
                if(indexArr==1){
                    $('#h_receipt_type').val(1)
                    $('.receipt_info').show();
                }

            }
        });

        $('.to_pay').click(function () {
            var leavemessage=$('#leavemessage').val();
            var h_receipt=$('#h_receipt').val();
            var h_receipt_type=$('#h_receipt_type').val();
            var receipt_info_name=$('#receipt_info_name').val();
            var receipt_info_code=$('#receipt_info_code').val();
            var address_list=$('#address_list').val();
            if(h_receipt_type==1&&h_receipt==1){
                if(receipt_info_name==''||receipt_info_code==''){
                    layer.msg('请填写完整的发票信息');
                    return;
                }
            }
            if(address_list==0){
                layer.msg('请添加收货地址');
            }else{
                $.ajax({
                    type: "POST",
                    url: "{:url('shop/order/dopay')}",
                    data: {
                        h_receipt:h_receipt,
                        h_receipt_type:h_receipt_type,
                        receipt_info_name:receipt_info_name,
                        receipt_info_code:receipt_info_code,
                        leavemessage:leavemessage
                    },
                    dataType: "json",
                    success: function (data) {
                        layer.msg(data.msg);
                        if(data.code==1){
                            location.href=data.url;
                        }
                    }
                })
            }
        })
    })
</script>
</html>
